/**
 * Created by hms on 2020-08-21.
 * 登录模块
 */
import { setCookie,delCookie } from '@/utils/cookie.js'

export const Login = {
    state:{
        username:'',
        session_id:'',
        role_id:'',
        user_id:'',
        is_grid:0   //是否是网格员
    },
    mutations:{
        setLogin(state,info){
            state.username = info.username;
            state.session_id = info.session_id;
            state.role_id=info.role_id;
            state.user_id=info.user_id;
            state.is_grid=info.is_grid;
        }
    },
    actions:{
        //登录
        loadLogin(context,info){
            for(var key in info){
                setCookie(key,info[key]);
            }
            context.commit('setLogin',info);
        },
        loadLogout(context,data){
            let arr=['username','session_id','user_id','role_id','is_grid'];
            for(var key in arr){
               delCookie(arr[key]);
            }
        }
    },
    getters:{
        getLoginUsername: state =>{
            return state.username
        },
        getSessionId: state =>{
            return state.session_id
        },
        getLoginRoleId: state =>{
            return state.role_id
        },
        getLoginUserId: state =>{
            return state.user_id
        },
        getLoginIsGrid: state =>{
            return state.is_grid
        }
    }
}
